package com.zxl.live.screen.call.ui.widget;

import android.content.Context;
import android.support.percent.PercentRelativeLayout;
import android.util.AttributeSet;

import com.zxl.live.screen.R;
import com.zxl.live.screen.call.helper.PreviewAnimHelper;
import com.zxl.live.screen.call.helper.ThemeHelper;

/**
 * Created by Administrator on 2017/12/11.
 */

public class CallFlashPanel extends PercentRelativeLayout implements InCallActionView.OnCallActionClickListener {

    private InCallActionView actionView;

    private ThemePreviewWindow previewWindow;

    private PreviewAnimHelper mPreviewAnimHelper;

    private InCallActionView.OnCallActionClickListener mOnCallActionClickListener;

    public CallFlashPanel(Context context, AttributeSet attrs) {
        super(context, attrs);
        mPreviewAnimHelper = new PreviewAnimHelper(0);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        previewWindow = (ThemePreviewWindow) findViewById(R.id.card_flash_preview_window);
        actionView = (InCallActionView) findViewById(R.id.card_in_call_action_view);
        actionView.setOnCallActionClickListener(this);
    }

    public void inCall(String number) {
        mPreviewAnimHelper.startAnim(previewWindow, actionView);
        actionView.setAutoRun(true);
        actionView.setInfo(ThemeHelper.yesPath, ThemeHelper.noPath);
        previewWindow.setNumber(number);
        previewWindow.play(ThemeHelper.type, ThemeHelper.flashPath);
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        actionView.setAutoRun(false);
        previewWindow.stop();
    }

    public void setOnCallActionClickListener(InCallActionView.OnCallActionClickListener mOnCallActionClickListener) {
        this.mOnCallActionClickListener = mOnCallActionClickListener;
    }

    @Override
    public void onAcceptClick() {
        if (null != mOnCallActionClickListener) {
            mOnCallActionClickListener.onAcceptClick();
        }
    }

    @Override
    public void onRejectClick() {
        if (null != mOnCallActionClickListener) {
            mOnCallActionClickListener.onRejectClick();
        }
    }
}
